package ui.home.column1

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import model.enums.ContentType
import model.enums.MenuItem
import theme.EasyChatTheme
import ui.compose.RectIconButton
import ui.home.HomeViewModel


/**
 * @author wei kunJie
 * @date 2024/3/11 13:28:27
 */
@Composable
fun LeftFunMenu(
    easyChatTheme: MutableState<EasyChatTheme>,
    selectItemId: MutableState<MenuItem>,
    column3ContentType: MutableState<ContentType>,
    viewModel: HomeViewModel
) {

    Spacer(modifier = Modifier.fillMaxWidth().height(18.dp))
    //消息
    RectIconButton(
        onClick = {
            //点击消息
            selectItemId.value = MenuItem.Chat
            val exist = viewModel.messageList.find { viewModel.msgListItemSelectId.value == it.id }
            if (viewModel.msgListItemSelectId.value == 0L || viewModel.messageList.size == 0 || exist == null) {
                column3ContentType.value = ContentType.NONE
            } else {
                column3ContentType.value = ContentType.FriendChat
            }
        },
        modifier = Modifier.size(40.dp)
            .clip(RoundedCornerShape(8.dp))
            .background(color = if (selectItemId.value == MenuItem.Chat) easyChatTheme.value.leftMenuSelectedColor else Color.Transparent),
    ) {
        Icon(
            painter = painterResource("icon/ic_menu_item_msg.svg"),
            contentDescription = "消息",
            tint = if (selectItemId.value == MenuItem.Chat) easyChatTheme.value.mainColor else Color(0XFF000000),
            modifier = Modifier.size(40.dp).padding(5.dp)
        )
    }

    Spacer(modifier = Modifier.fillMaxWidth().height(8.dp))
    //联系人
    RectIconButton(
        onClick = {
            //点击联系人
            selectItemId.value = MenuItem.Friends
            column3ContentType.value = ContentType.NONE
        },
        modifier = Modifier.size(40.dp).clip(RoundedCornerShape(8.dp))
            .background(color = if (selectItemId.value == MenuItem.Friends) easyChatTheme.value.leftMenuSelectedColor else Color.Transparent),
    ) {
        Icon(
            painter = painterResource("icon/ic_menu_item_users.svg"),
            contentDescription = "联系人",
            tint = if (selectItemId.value == MenuItem.Friends) easyChatTheme.value.mainColor else Color(0XFF000000),
            modifier = Modifier.size(40.dp).padding(5.dp)
        )
    }
}